package com.siwei.mes.controller.experiment;

import com.siwei.mes.common.annotation.AnonymousAccess;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.entity.experiment.OpenAppraisal;
import com.siwei.mes.service.experiment.OpenAppraisalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 开盘鉴定表相关
 *
 * @author yangke
 * @since 2024-11-23 10:50:05
 */
@Api(value = "开盘鉴定表")
@RestController
@RequestMapping("openAppraisal")
public class OpenAppraisalController {
    @Resource
    private OpenAppraisalService openAppraisalService;

    @ApiOperation(value = "新增开盘鉴定表")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) OpenAppraisal entity) {
        return Json.succ().data(ApiResult.addColumn("id", openAppraisalService.create(entity)));
    }

    @ApiOperation(value = "修改开盘鉴定表")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) OpenAppraisal entity) {
        openAppraisalService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除开盘鉴定表")
    @PostMapping("/delete")
    public Json delete(@RequestBody OpenAppraisal entity) {
        openAppraisalService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取开盘鉴定表")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<OpenAppraisal, OpenAppraisal> query) {
        return Json.succ().data(openAppraisalService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取开盘鉴定表")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(openAppraisalService.loadById(id));
    }

    @ApiOperation(value = "根据主键id获取开盘鉴定表绑定的抗压台账")
    @GetMapping("loadKyExperimentExById")
    public Json loadKyExperimentExById(@RequestParam("id") Long id) {
        return Json.succ().data(openAppraisalService.loadKyExperimentById(id));
    }

    @ApiOperation(value = "获取所有开盘鉴定表")
    @PostMapping("getAll")
    public Json getAll(@RequestBody OpenAppraisal entity) {
        return Json.succ().data(ApiResult.addList(openAppraisalService.getAll(entity)));
    }

    @AnonymousAccess
    @ApiOperation(value = "修改开盘鉴定的配合比信息")
    @GetMapping("updateOpenAppraisalPhb")
    public Json updateOpenAppraisalPhb() {
        openAppraisalService.updateOpenAppraisalPhb();
        return Json.succ().data(new ApiResult());
    }

    @AnonymousAccess
    @ApiOperation(value = "重新生成所有开盘鉴定信息")
    @GetMapping("cleanOpenAppraisal")
    public Json cleanOpenAppraisal() {
        openAppraisalService.cleanOpenAppraisal();
        return Json.succ().data(new ApiResult());
    }
}
